package com.drug.mingkang.service.impl;

import com.drug.mingkang.model.HqRawmaterial;
import com.drug.mingkang.Mapper.HqRawmaterialMapper;
import com.drug.mingkang.service.HqRawmaterialService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * 原材料(HqRawmaterial)表服务实现类
 *
 * @author wenchangjian
 * @since 2020-08-11 11:28:43
 */
@Service("hqRawmaterialService")
public class HqRawmaterialServiceImpl implements HqRawmaterialService {
    @Resource
    private HqRawmaterialMapper hqRawmaterialMapper;

    /**
     * 通过ID查询单条数据
     *
     * @param materialId 主键
     * @return 实例对象
     */
    @Override
    public HqRawmaterial queryById(String materialId) {
        return this.hqRawmaterialMapper.queryById(materialId);
    }

    /**
     * 查询多条数据
     *
     * @param offset 查询起始位置
     * @param limit 查询条数
     * @return 对象列表
     */
    @Override
    public List<HqRawmaterial> queryAllByLimit(int offset, int limit) {
        return this.hqRawmaterialMapper.queryAllByLimit(offset, limit);
    }

    /**
     * 新增数据
     *
     * @param hqRawmaterial 实例对象
     * @return 实例对象
     */
    @Override
    public HqRawmaterial insert(HqRawmaterial hqRawmaterial) {
        this.hqRawmaterialMapper.insert(hqRawmaterial);
        return hqRawmaterial;
    }

    /**
     * 修改数据
     *
     * @param hqRawmaterial 实例对象
     * @return 实例对象
     */
    @Override
    public HqRawmaterial update(HqRawmaterial hqRawmaterial) {
        this.hqRawmaterialMapper.update(hqRawmaterial);
        return this.queryById(hqRawmaterial.getMaterialId());
    }

    /**
     * 通过主键删除数据
     *
     * @param materialId 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(String materialId) {
        return this.hqRawmaterialMapper.deleteById(materialId) > 0;
    }
}